//---------------------------------------------------------------------------

#ifndef CCompressH
#define CCompressH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <Sysutils.hpp>
#include <ComCtrls.hpp>
#include <stdio.h>
#include "Outils.h"
//---------------------------------------------------------------------------
#include "libtar.hpp"
//---------------------------------------------------------------------------
#define BZ_OK                0
#define BZ_RUN_OK            1
#define BZ_FLUSH_OK          2
#define BZ_FINISH_OK         3
#define BZ_STREAM_END        4
#define BZ_SEQUENCE_ERROR    (-1)
#define BZ_PARAM_ERROR       (-2)
#define BZ_MEM_ERROR         (-3)
#define BZ_DATA_ERROR        (-4)
#define BZ_DATA_ERROR_MAGIC  (-5)
#define BZ_IO_ERROR          (-6)
#define BZ_UNEXPECTED_EOF    (-7)
#define BZ_OUTBUFF_FULL      (-8)
#define BZ_CONFIG_ERROR      (-9)

//---------------------------------------------------------------------------
typedef int   (WINAPI *TFctRead)        (int*, void*, void*, int);
typedef void* (WINAPI *TFctReadOpen)    (int*, FILE*, int, int, void*, int);
typedef void  (WINAPI *TFctReadClose)   (int* , void* );

typedef void  (WINAPI *TFctWrite)       (int*, void*, void*, int);
typedef void* (WINAPI *TFctWriteOpen)   (int*, FILE*, int, int, int );
typedef void  (WINAPI *TFctWriteClose)  (int*, void*, int, unsigned int*, unsigned int* );


typedef void  (WINAPI *TFctGetUnused)   (int*, void*, void**, int* );

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
typedef void __fastcall (__closure *TPourcentEvent)( TObject *Sender, int nPourcent, const AnsiString &asMsg );
typedef void __fastcall (__closure *TRestaureEvent)( TObject *Sender, AnsiString asMotDePasse );
//---------------------------------------------------------------------------

class PACKAGE_OUTILS CCompress : public TComponent
{
private:
    AnsiString m_asDirectory;
    AnsiString m_asDirectoryOut;
    AnsiString m_asPathTemp;
    AnsiString m_asFileName;
    AnsiString m_asMotDePasse;
    int m_nPourcent;

    TPourcentEvent FOnPourcent;
    TRestaureEvent FOnRestaure;

    int nbTotalFiles;

private:	// Déclarations utilisateur
    void __fastcall CreerFichierTAR(const AnsiString &asDirectory);
    int  __fastcall AddTAR( TTarWriter *tarwriter, const AnsiString &asDir, int nNum = 0);

    void __fastcall SetDirectory   (AnsiString asDirectory   );
    void __fastcall SetDirectoryOut(AnsiString asDirectoryOut);

    bool __fastcall Compress( void );
    bool __fastcall Decompress( void );

public:		// Déclarations utilisateur
    __fastcall CCompress(TComponent* Owner);
    virtual __fastcall ~CCompress();

    void __fastcall Compresser(TStringList *lstRepertoire);
    void __fastcall Compresser( void );
    void __fastcall Decompresser( void );

__published:		// Déclarations utilisateur
    __property        int Pourcent     = {read = m_nPourcent};
    __property AnsiString Directory    = {read = m_asDirectory,     write = SetDirectory};
    __property AnsiString DirectoryOut = {read = m_asDirectoryOut,  write = SetDirectoryOut};
    __property AnsiString FileName     = {read = m_asFileName,      write = m_asFileName};
    __property AnsiString MotDePasse   = {read = m_asMotDePasse,    write = m_asMotDePasse};

    __property TPourcentEvent OnPourcent = { read = FOnPourcent,    write = FOnPourcent };
    __property TRestaureEvent OnRestaure = { read = FOnRestaure,    write = FOnRestaure };
};
//---------------------------------------------------------------------------
#endif
